import 'package:flutter/material.dart';
import 'dart:developer' as developer;
import 'package:oktoast/oktoast.dart';
import 'package:testui/test04/text/TextLearn.dart';
import 'package:testui/test04/button/ButtonLearn.dart';
import 'package:testui/test04/image/imagelearn.dart';
import 'package:testui/test04/icon/iconsLearn.dart';
import 'package:testui/test04/check/checkLearn.dart';
import 'package:testui/test04/input/textFieldLearn.dart';
import 'package:testui/test04/form/formPage.dart';
import 'package:testui/test04/layout/learnLayout.dart';
import 'package:testui/test04/container/learnAllcontainer.dart';
import 'package:testui/test04/scroll/learnScrollAll.dart';





///
///   官方控件   https://flutter.cn/docs/reference/widgets
///
///   第三方网站  http://laomengit.com/
///
class LearnApp07 extends StatelessWidget{
  const LearnApp07({super.key});

  @override
  Widget build(BuildContext context) {


    return  OKToast(child: MaterialApp(
      title: "常用组件列表",
      home: ListPage(),
    ),position: ToastPosition.bottom,);
  }

}


class ListPage extends StatelessWidget{
  final List<String>   list = [
    "文本Text","按钮Button","图片Image","图标Icon","选择类组件",
    "输入框组件","表单组件","布局类组件",
    "容器类组件","可滚动组件","功能性组件"];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("主页"),
      ),
      body: Center(
        child: getListData(),
      ),
    );
  }


  Widget getListData() {


   return ListView.builder(
      padding:const EdgeInsets.all(5.0),
      scrollDirection: Axis.vertical,
      itemCount: list.length,
      itemBuilder: (BuildContext context, int index){
        return ListItemView(index: index, title: list[index]);
      },
    );


  }

}

class ListItemView extends StatelessWidget{
  final int index ;
  final String title;


  const ListItemView({super.key, required this.index,required this.title});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Card(
        child: Container(
          child:  Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            mainAxisSize: MainAxisSize.min,
            children: [
              Text("序号：${index+1}"),
              Text('$title',style:TextStyle(
                  fontSize: 20
              ),)
            ],
          ),
          margin:const EdgeInsets.all(4),
        ),
    ),
      onTap: (){
          pushNextPage(context);
      },
    );
  }

  void pushNextPage(BuildContext context) {


    Navigator.of(context).push(MaterialPageRoute(builder:(context) {
      if(index==0){
        return TextPage();
      }else  if(index==1){
        return ButtonPage();
      }else  if(index==2){
        return ImagePage();
      }else  if(index==3){
        return IconPage();
      }else  if(index==4){
        return CheckPage();
      }else  if(index==5){
        return TextFieldPage();
      }else  if(index==6){
        return FormPage();
      }else  if(index==7){
        return LayoutPage();
      }else  if(index==8){
        return AllContainerListPage();
      }else  if(index==9){
        return AllScrollListPage();
      }else{
        return TextPage();
      }
    }));



  }

}